Skip to content

fix: prevent invalid SQL when creating publication with no publish operations#1068

Open
selenaalpha77-sketch wants to merge 1 commit intosupabase:masterfrom
selenaalpha77-sketch:fix/publication-empty-publish-list
Open

fix: prevent invalid SQL when creating publication with no publish operations#1068
selenaalpha77-sketch wants to merge 1 commit intosupabase:masterfrom
selenaalpha77-sketch:fix/publication-empty-publish-list

Conversation

@selenaalpha77-sketch
Copy link
Copy Markdown

Problem

When create() is called with all publish flags set to false (their default), the generated SQL is:

CREATE PUBLICATION my_pub FOR ALL TABLES
  WITH (publish = '');

PostgreSQL rejects WITH (publish = '') because the publish list must be non-empty. This causes a runtime database error.

Reported in: supabase/supabase#45020

Fix

Omit the WITH (publish = ...) clause entirely when no publish operations are specified. PostgreSQL then uses its default behavior: publish all operations (insert, update, delete, truncate).

// Before
const sql = `CREATE PUBLICATION ${ident(name)} ${tableClause}
  WITH (publish = '${publishOps.join(',')}');`

// After
const publishClause =
  publishOps.length > 0 ? \`WITH (publish = '\${publishOps.join(',')}')\` : ''
const sql = `CREATE PUBLICATION ${ident(name)} ${tableClause}
  ${publishClause};`

Test

Added a regression test: create with no publish operations uses PostgreSQL defaults that verifies:

  1. No error is returned
  2. All four publish flags default to true (PostgreSQL's default)

🤖 Generated with Claude Code

…erations

When all publish_* flags are false (the default), the CREATE PUBLICATION
statement was generating `WITH (publish = '')` which PostgreSQL rejects
as invalid — the publish list must be non-empty.

Fix: omit the WITH clause entirely when no publish operations are
specified. PostgreSQL then uses its default (all operations: insert,
update, delete, truncate), which is the sensible fallback.

Also add a regression test covering this case.

Fixes supabase/supabase#45020

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant